<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/WEB-INF/common/hplus-css.jsp"%>
<link rel="shortcut icon" href="${path}/favicon.ico" rel="stylesheet">
<link href="${path}/assets/hplus/css/bootstrap.min.css?v=3.3.6"
    rel="stylesheet">
<link href="${path}/assets/hplus/css/font-awesome.min.css?v=4.4.0"
    rel="stylesheet">
<link href="${path}/assets/hplus/css/animate.css" rel="stylesheet">
<link href="${path}/assets/hplus/css/style.css?v=4.1.0" rel="stylesheet">
<link href="${path}/assets/hplus/css/font-awesome.min.css?v=4.4.0"
    rel="stylesheet">
<link href="${path}/assets/hplus/css/plugins/jsTree/style.min.css"
    rel="stylesheet">
<link href="${path}/assets/hplus/css/plugins/jqgrid/ui.jqgrid.css?0820"
    rel="stylesheet">
</head>
<body class="gray-bg">
     <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <form action="${path}/role/add" class="form-horizontal m-t" id="roleForm" method="post">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">角色名称：</label>
                                <div class="col-sm-8">
                                    <input type="text" id="nameZh" name="nameZh" minlength="2" class="form-control" required="">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">标识：</label>
                                <div class="col-sm-8">
                                    <input type="text" id="nameEn" name="nameEn" class="form-control" required="">
								</div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">状态：</label>
                                <div class="col-sm-8">
                                     <select class="form-control" id="status" name="status">
	                                    <option value="1">启用</option>
	                                    <option value="0">禁用</option>
	                                </select>
                                </div>
                            </div>
                             <div class="form-group">
                                <label class="col-sm-3 control-label">角色所属类型：</label>
                                <div class="col-sm-8" id="cat" class="form-control">
                                    <c:if test="${user.type=='1'}">
                                        <select class="form-control"  name="category">
                                            <option value="1">系统管理</option>
                                            <option value="4">组织机构用户</option>
                                            <option value="2">普通平台用户</option>
                                        </select>
                                    </c:if>
                                    <c:if test="${user.type=='3'}">
                                        <select class="form-control"  name="category">
                                            <option value="4">组织机构用户</option>
                                        </select>
                                    </c:if>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">权限：</label>
                                <div class="col-sm-8">
			                        <div id="using_json"></div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-3">
                                    <button class="btn btn-primary" id="add-btn" type="button">添加角色</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
     <%@include file="/WEB-INF/common/hplus-js.jsp"%>
    <!-- Peity -->
    <script src="${path}/assets/hplus/js/plugins/peity/jquery.peity.min.js"></script>
    <script src="${path}/assets/hplus/js/content.js"></script>
    <script src="${path}/assets/hplus/js/plugins/jsTree/jstree.min.js"></script>
    <!-- jqGrid -->
    <script src="${path}/assets/hplus/js/plugins/jqgrid/i18n/grid.locale-cn.js?0820"></script>
    <script src="${path}/assets/hplus/js/plugins/jqgrid/jquery.jqGrid.min.js?0820"></script>
    <script type="text/javascript">
      
        $(function(){
            $("#using_json").jstree({
                "core": {
                	'data' : function (obj, callback) {
                        var jsonstr="[]";
                        var jsonarray = eval('('+jsonstr+')');
                        $.ajax({
                            type: "POST",
                            url:"${path}/menu/query",
                            dataType:"json",
                            async: false,
                            success:function(result) {
                                var arrays= result;
                                for(var i=0 ; i<arrays.length; i++){
                                    var arr = {
                                       "id":arrays[i].id,
                                       "parent":arrays[i].pid?arrays[i].pid:"#",
                                       "text":arrays[i].name,
                                       "icon" : "fa fa-folder"
                                    }
                                    jsonarray.push(arr);
                                }
                            }
                        });
                        callback.call(this, jsonarray);
                    }
                },
                
                "checkbox" : {
                    "keep_selected_style" : false
                },
                "plugins" : [ "wholerow", "checkbox" ]
            })
        });
        
        
        $(document).ready(function () {
        	$("#roleForm").validate();
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
            $("#add-btn").click(function(){
            	 var chenked=$("#cat input[type='checkbox']:checked").val([]);//此为重点  
                 var category = "";  
                 for(var i=0;i<chenked.length;i++){  
                	 if (i<(chenked.length-1)) {
                		 category += chenked[i].value +",";
					}else{
						category += chenked[i].value;
					}
                 }
                $("input[name='category']").val(category);
                 
            	var valid = $("#roleForm").valid();
            	if(valid){
            		parent.layer.msg('正在提交请稍候......', {icon: 16,time: 2000,shade : [0.5 , '#000' , true]});
            		var nodes = new Array();
           		     nodes=$("#using_json").jstree("get_checked");
           		 	
           		 	//var data = {mensId:nodes};
           		 	//formSubmit("roleForm",data);
           		 	
           		 $("#roleForm").ajaxSubmit({
                     dataType: "json",
                     data:{mensId: nodes},
                     traditional: true,//必须指定为true
                     success: function (json) {
                         var code = json.code;
                         if (code == 0) {
                             layer.msg('添加成功:' + json.msg, {
                                 icon: 1
                             });
                             setTimeout(function () {
                                 window.location.reload();
                                 parent.layer.closeAll();
                             }, 1000);
                         } else {
                             layer.msg('发生错误:' + json.msg, {
                                 icon: 5
                             });
                         }
                     },
                     error: function () {
                         layer.msg('发生错误', {
                             icon: 5
                         });
                     }
                     
                 });
            	}else{
            		layer.msg("请填写完整信息！！！！", {
        				icon : 5
        			});
                }
            });
        });
    </script>
</body>
</html>
